3248. 矩阵中的蛇
为保证权益,题目请参考 3248. 矩阵中的蛇(From LeetCode).
解决方案1
Python
python
from typing import List
class Solution:
def finalPositionOfSnake(self, n: int, commands: List[str]) -> int:
ans = 0
for c in commands:
if c[0] == "U":
ans -= n
elif c[0] == 'D':
ans += n
elif c[0] == 'L':
ans -= 1
else:
ans += 1
return ans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15